<?php
declare (strict_types = 1);

namespace app\admin\controller;

use app\common\controller\Backend;
use hg\apidoc\annotation as Apidoc;
use think\facade\Db;

/**
 * 操作日志
 * @Apidoc\Group("base")
 * @package app\admin\controller
 */
class OpLog extends Backend
{
    /**
     * 初始化参数
     * @author 贾二小
     * @since 2021/7/3
     */
    public function initialize()
    {
        $this->config = [
            'name'=>'操作日志',
            'table_name'=>'op_log',//表名
            'table_alias' => 'a',//别名
            'search_table'=> null,//关联表时，需要重写
            'is_limit'=> true,//是否分页显示
            'search_field' => 'id,name,op_type,success,message,ip,location,browser,os,url,class_name,method_name,req_method,param,result,op_time,account',//查询表格字段
            'search_param'=>[
                ['field' => 'name', 'type' => '=', 'param'=> 'name'],
                ['field' => 'op_type', 'type' => '=', 'param'=> 'op_type'],
                ['field' => 'success', 'type' => '=', 'param'=> 'success'],
                ['field' => 'op_time', 'type' => 'between', 'param'=> ['begin_time','end_time']],
            ],//查询表格条件
            'is_delete'=> false,//是否假删除
            'id_validated' => [
                'id' => ['msg' => 'ID不能为空', 'regex' => false, 'pcre' => '',],
            ],//表单验证
        ];
        parent::initialize(); // TODO: Change the autogenerated stub
    }

    /**
     * @Apidoc\Title("操作日志清空")
     * @Apidoc\Desc("操作日志表清空")
     * @Apidoc\Method("POST")
     * @Apidoc\Tag("测试 基础")
     * @Apidoc\Url("/admin/op_log/delete")
     * @author 贾二小
     * @since 2021/7/10
     */
    public function delete()
    {
        //清空表
        Db::execute("TRUNCATE {$this->config['table_name']}");
        //日志
        $this->sLog($this->config['name'].'_清空',"成功");
        $this->success();
    }

    /**
     * 日志查看
     * @author 贾二小
     * @since 2021/6/29
     */
    public function detail()
    {
        return view();
    }
}